package com.wugh.fast.demo.config;

import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * 说明:
 *
 * @author wugh
 * @date 2019-11-20 16:57
 */
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        //给header添加参数token
        ParameterBuilder tokenPar = new ParameterBuilder();
        tokenPar.name("Authorization").description("OAuth2授权信息:bearer token").modelRef(new ModelRef("string")).parameterType("header").defaultValue("bearer ").required(true).build();
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("用户权限管理系统")
                        .description("用户、公司、权限等管理操作")
                        .version("1.0.0").build()
                )
                // 是否开启
                .select()
                // 扫描的路径包
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                // 指定路径处理PathSelectors.any()代表所有的路径
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(Lists.newArrayList(tokenPar.build()));
    }
}
